#include "data_flood.h"
#include <stdlib.h>
#include <time.h>

int16 random_int16_maker(void)
{
    int16 result = 0;

    result = rand() % 0x7fff;

    return result;
}

int random_int_maker(void)
{
    int result = 0;

    result = rand() % 0x0fffffff;

    return result;
}

int64 random_int64_maker(void)
{
    int64 result = 0;

    result = rand() % 0x0fffffffffffffff;

    return result;
}

char* random_string_maker(void)
{
    char* result = 0;

    result = random_str();

    return result;
}

char* random_float_maker(void)
{
    char*   result = NULL;
    uint16  h_n = random_int16_maker();
    uint16  l_n = random_int16_maker();

    memset(num_buff, 0, NUMBER_BUFF_LEN);
    sprintf(num_buff, "%d.%d", (int)(h_n % 1000), (int)(l_n % 1000));
    result = strdup(num_buff);

    return result;
}

char* random_timestamp_maker(void)
{
    struct tm t;
	time_t now;
    char*   result = NULL;

	time(&now);
	localtime_r(&now, &t);

    memset(num_buff, 0, NUMBER_BUFF_LEN);
    sprintf(num_buff, "%d-%d-%d %d:%d:%d", t.tm_year + 1900, t.tm_mon + 1, t.tm_mday,
                            t.tm_hour, t.tm_min, t.tm_sec);
    result = strdup(num_buff);

    return result;
}

char* random_date_maker(void)
{
    struct tm t;
	time_t now;
    char*   result = NULL;

	time(&now);
	localtime_r(&now, &t);

    memset(num_buff, 0, NUMBER_BUFF_LEN);
    sprintf(num_buff, "%d-%d-%d", t.tm_year + 1900, t.tm_mon + 1, t.tm_mday);
    result = strdup(num_buff);

    return result;
}

char* random_time_maker(void)
{
    struct tm t;
	time_t now;
    char*   result = NULL;

	time(&now);
	localtime_r(&now, &t);

    memset(num_buff, 0, NUMBER_BUFF_LEN);
    sprintf(num_buff, "%d:%d:%d", t.tm_hour, t.tm_min, t.tm_sec);
    result = strdup(num_buff);

    return result;
}

char* random_bool_maker(void)
{
    bool value = (rand() % 2 == 0);
    char*   result = NULL;

    if(value)
        result = strdup("t");
    else
        result = strdup("f");
    
    return result;
}